package cn.hou.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.junit.Test;

import cn.hou.java8.Employee;
import cn.hou.java8.Employee.STATUS;

public class TestStreamAPI4 {
	//1 给定一个数字列表,返回一个由数字平方构成的列表
	@Test
	public void test01(){
		List<Integer> asList = Arrays.asList(1,2,3,4,5);
		List<Integer> collect = asList.stream().map(x->x*x).collect(Collectors.toList());
		System.out.println(collect);//[1, 4, 9, 16, 25]
	}
	private List<Employee> emps = Arrays.asList(
			new Employee(102, "李四", 59, 6666.66,STATUS.BUBY),
			new Employee(101, "张三", 18, 9999.99,STATUS.FREE),
			new Employee(103, "王五", 28, 3333.33,STATUS.LEAVE),
			new Employee(104, "赵六", 8, 7777.77,STATUS.BUBY),
			new Employee(104, "赵六", 8, 7777.77,STATUS.BUBY),
			new Employee(104, "赵六", 8, 7777.77,STATUS.FREE),
			new Employee(105, "田七", 38, 5555.55,STATUS.BUBY)
	);
	//2 用map-reduce计算出流中有多少个员工
	@Test
	public void test02(){
		Optional<Integer> reduce = emps.stream().map((x)->1).reduce(Integer::sum);
		System.out.println(reduce.get());  //7
		
	}
}
